import request from '@/utils/request';
import { getCurrentInstance } from 'vue';
const errortips =
  getCurrentInstance()?.appContext.config.globalProperties.$errortips;

/**
 * 分页查询用户
 */
/* export async function get_note_list(params) {
  const res = await request.post('/order/sales_note/get_list', {
    ...params
  });
  if (res.data.code === 1) {
    return {
      list: res.data.data.row_list,
      columns: res.data.data.columns,
      searchData: res.data.data.search_area,
      count: res.data.data.page_info?.total,
      top_button: res.data.data.top_button
    };
  }
  return Promise.reject(res.data.msg);
} */
export async function get_member_select(params) {
  const res = await request.post('/member/member/select_list', {
    ...params
  });
  if (res.data.code === 1) {
    let columns = [];
    columns.push({
      name: 'name',
      field: 'name',
      title: '姓名',
      type: 'text'
    });
    columns.push({
      name: 'nickname',
      field: 'nickname',
      title: '昵称',
      type: 'text'
    });
    columns.push({
      name: 'mobile',
      field: 'mobile',
      title: '手机号',
      type: 'text'
    });
    console.log(columns);
    return {
      list: res.data.data.row_list,
      columns: columns,
      searchData: res.data.data.search_area,
      count: res.data.data.page_info?.total,
      top_button: res.data.data.top_button
    };
  }
  return Promise.reject(res.data.msg);
}
export async function get_goods_details(params) {
  const res = await request.post('/order/order/goods_details', {
    ...params
  });
  if (res.data.code === 1) {
    return res.data.data;
  }
  console.log('res===', res);
  return Promise.reject(res.data.msg);
}
export async function get_note_list(params) {
  const res = await request.post('/order/sales_note/get_list', {
    ...params
  });
  if (res.data.code === 1) {
    return res.data.data;
  }
  return Promise.reject(res.data.msg);
}
export async function add_note(params) {
  const res = await request.post('/order/sales_note/add', {
    ...params
  });
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}
export async function edit_note(params) {
  const res = await request.post('/order/sales_note/edit', {
    ...params
  });
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}
export async function delete_note(params) {
  const res = await request.post('/order/sales_note/delete', {
    ...params
  });
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}
export async function salesman_list(params) {
  const res = await request.post('/order/order/salesman_list', {
    ...params
  });
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}
export async function store_team(params) {
  const res = await request.post('/order/order/store_team', {
    ...params
  });
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}
export async function jewelry_order(params) {
  const res = await request.post('/order/order/jewelry_order', {
    ...params
  });
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg || errortips);
}
export async function been_order(params) {
  const res = await request.post('/order/order/been_order', {
    ...params
  });
  if (res.data.code === 1) {
    return res.data.data;
  }
  return Promise.reject(res.data.msg);
}
export async function del_been_order(params) {
  const res = await request.post('/order/order/del_been_order', {
    ...params
  });
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}
//去收款
export async function go_pay(params) {
  const res = await request.post('/order/order/go_pay', {
    ...params
  });
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}
//挂单
export async function go_maker(params) {
  const res = await request.post('/order/order/maker', {
    ...params
  });
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}
//获取赠送积分
export async function get_points(params) {
  const res = await request.post('/order/order/get_points', {
    ...params
  });
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}
//提交赠送积分
export async function set_points(params) {
  const res = await request.post('/order/order/set_points', {
    ...params
  });
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}
//取消赠送积分
export async function cancel_points(params) {
  const res = await request.post('/order/order/cancel_points', {
    ...params
  });
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}

/*-------------------- 旧货换购 ---------------*/
//获取购买商品
export async function get_buy(params) {
  const res = await request.post('/order/junk_exchange/get_buy', {
    ...params
  });
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}

//获取购买商品详情
export async function get_buy_detail(params) {
  const res = await request.post('/order/junk_exchange/get_buy_detail', {
    ...params
  });
  if (res.data.code === 1) {
    return res.data.data;
  }
  return Promise.reject(res.data.msg);
}
//旧货换购
export async function junk_exchange(params) {
  const res = await request.post('/order/junk_exchange/junk_exchange', {
    ...params
  });
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}

/*------------------- 新品换购 ------------------------*/
//获取购买商品
export async function get_new_exchange_buy(params) {
  const res = await request.post('/order/new_exchange/get_buy', {
    ...params
  });
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}
//获取购买商品详情
export async function get_new_exchange_detail(params) {
  const res = await request.post('/order/new_exchange/get_buy_detail', {
    ...params
  });
  if (res.data.code === 1) {
    return res.data.data;
  }
  return Promise.reject(res.data.msg);
}
//新品换购
export async function new_exchange(params) {
  const res = await request.post('/order/new_exchange/new_exchange', {
    ...params
  });
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}

/* --------------------旧货回收-------------------------- */
export async function junk_recovery(params) {
  const res = await request.post('/order/junk_exchange/junk_recovery', {
    ...params
  });
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}
